$(function (){
    $('#loginForm').submit(function (){
        let agree = $("#agree").prop("checked")
        if(!agree){
            alert("未同意协议,不能登录")
            return  false;
        }
        // 同意协议 可以登录
        let username = $("#username").val();
        let password = $("#password").val();
        password = md5(password)
        let jsonLogin = JSON.stringify({username,password});
        console.log(jsonLogin)
        $.ajax({
            url:'/api/user/login',
            type:"post",
            dataType:'json',
            contentType:'application/json;charset=utf-8',
            data:jsonLogin,
            success:function (result){
                console.log(result)
                // alert(result['msg']);
                // if(result['code']==1008){
                //     // 登录成功
                //     window.location.href = "/index.html"
                // }
                let layer = layui.layer

                if(result['code']==1008){
                    layer.alert(result['msg'],function (index){
                        layer.close(index)
                        window.location.href = "/index.html"
                    })
                }else{
                    layer.alert(result['msg'],function (index){
                        layer.close(index)
                    })
                }

            }
        })
        return false;
    })
})